/**
 * 加载数据
 */
function loadData(pageSize, method, formData) {
    $("#data").datagrid({
        url: '/management/wes/gzh/query',
        method: method || 'GET',
        queryParams: formData || '',
        height: 'auto',
        fit: true,
        fitColumns: true,
        striped: true,
        rownumbers: true,
        border: true,
        singleSelect: true,
        pagination: false,
        pageSize: pageSize || 20,
        pageList: [10, 20, 50, pageSize || 0],
        showFooter: true,
        toolbar: '#tb',
        columns: [[{
            field: "docNumber",
            title: "单号",
            width: 50
        }, {
            field: "docCompname",
            title: "出版社",
            width: 50
        }, {
            field: "docStatus",
            title: "状态",
            width: 20
        }, {
            field: "status",
            title: "状态2",
            width: 20
        }, {
            field: "docConskQty",
            title: "数量",
            width: 20
        }]]
    });
}

function formatZt(val, row, index) {
    if (val == "1") {
        return '<span style="color:green;">已回告</span>';
    } else if (val == "0") {
        return '<span style="color:red;">未回告</span>';
    } else {
        return val;
    }
}

function formatSendcode(val, row, index) {
    if (val == "1") {
        return '<span style="color:green;">发送成功</span>';
    } else if (val == "2") {
        return '<span style="color:red;">发送失败</span>';
    } else if (val == "0") {
        return '<span style="color:blue;">未发送</span>';
    } else {
        return val;
    }
}

function query() {
    var docNumber = $("#docNumber").val();
    var formData = {
        docNumber: docNumber,
    }
    loadData(20, 'POST', formData);
}

$(function () {
    loadData('', 'POST', '');
});

/**
 * 主配转货阁
 */
function updateJobsXso() {
    var row = $('#data').datagrid('getSelected');
    var id = row.docNumber;
    var formData = {
        "docNumber": id
    };
    $.ajax({
        type: 'Post',
        url: '/management/wes/gzh/updateJobsXso',
        data: formData,
        dataType: 'json',
        success: function (res) {
            if (res.status == 0) {
                $.messager.alert("提示", res.msg, "info", function () {
                    $("#data").datagrid('reload');
                    $("#w-editInfo").window("close");
                });
            }  else if (res.status == 10) {
                _util.doLogin();
            }else {
                $.messager.alert("提示", res.msg, "error");
            }
        },
        error: function () {
            $.messager.alert("提示", "数据错误，联系管理员", "error");
        }
    });
}

/**
 * 货阁转主配
 */

function updateJobsXso1() {
    var row = $('#data').datagrid('getSelected');
    var id = row.docNumber;
    var formData = {
        "docNumber": id
    };
    $.ajax({
        type: 'Post',
        url: '/management/wes/gzh/updateJobsXso1',
        data: formData,
        dataType: 'json',
        success: function (res) {
            if (res.status == 0) {
                $.messager.alert("提示", res.msg, "info", function () {
                    $("#data").datagrid('reload');
                    $("#w-editInfo").window("close");
                });
            }  else if (res.status == 10) {
                _util.doLogin();
            }else {
                $.messager.alert("提示", res.msg, "error");
            }
        },
        error: function () {
            $.messager.alert("提示", "数据错误，联系管理员", "error");
        }
    });
}



/**
 * 操作工具
 */
tool = {

    remove: function () {
        var row = $("#data").datagrid('getSelected');
        if (row == null) {
            $.messager.alert("操作提示", "没有选中的记录", "error");
            return;
        }
        $.messager.confirm("操作提示", "您确定要更改这条记录吗？", function () {
            updateJobsXso();
        });
    },
    update: function () {
        var row = $("#data").datagrid('getSelected');
        if (row == null) {
            $.messager.alert("操作提示", "没有选中的记录", "error");
            return;
        }
        $.messager.confirm("操作提示", "您确定要更改这条记录吗？", function () {
            updateJobsXso1();
        });
    },
    yes: function () {
        var row = $("#c_subcode").datagrid('getSelected');
        if (row == null) {
            $.messager.alert("操作提示", "没有选中的记录", "error");
            return;
        }
        $("#subcode").textbox('setValue', row.subcode);
        $("#showSubcode").window("close");
    },
    no: function () {
        $("#showSubcode").window("close");
    }
}
